<template>
	<view class="page">
		<navigation defaultButton="back" barColor="#333333" textColor="#333333">人员管理</navigation>
		<scroll-view scroll-y="true" class="page_scroll" scroll-with-animation="true" enable-back-to-top="true" @scrolltolower="scrollBottom">
			<view class="list">
				<view class="list_item" v-for="(item, index) in modelList" :key="index">
					<view class="list_left">
						<image class="photo" :src="item.wxAvatar" mode=""></image>
						<view class="info">
							<view class="name">{{ item.wxNickname }}</view>
							<view class="date">{{ item.gmtCreate | toDate('yyyy-MM-dd hh:mm') }}</view>
						</view>
					</view>
					<view class="list_right" v-if="item.instituteState == enums['成员审核状态']['待审核']">
						<view class="empyt_btn" @tap="audit(enums['审核成员审核状态']['驳回'], item.id)">拒绝通过</view>
						<view class="solid_btn" @tap="audit(enums['审核成员审核状态']['同意'], item.id)">通过审核</view>
					</view>
					<view class="list_right" v-if="item.instituteState == enums['成员审核状态']['已审核']"><view class="delete_btn" @tap="delStaff(item.id)">删除成员</view></view>
				</view>
			</view>
			<view class="no-data">
				<view class="more"><uni-load-more :status="moreStatus" :content-text="moreContentText" iconType="spinner" color="#666666"></uni-load-more></view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import * as orgApi from '@/api/orgApi/org.js';
import { uniLoadMore } from '@dcloudio/uni-ui';
export default {
	data() {
		return {
			enums: this.$enums,
			modelList: [],
			searchModel: {
				current: 1,
				size: 10
			},
			// more
			moreStatus: 'more',
			moreContentText: {
				// 加载各状态文字说明。
				contentdown: '加载更多',
				contentrefresh: '正在加载...',
				contentnomore: '没有更多了'
			}
		};
	},
	onShow() {
		this.getList();
	},
	methods: {
		delStaff(id) {
			if (id) {
				orgApi
					.delStaff({ id: id })
					.then(res => {
						if (res.code == 0) {
							this.searchModel.current = 1;
							this.getList();
						}
					})
					.catch(e => {
						uni.showToast({
							title: e.msg,
							icon: 'none',
							duration: 1000
						});
					});
			}
		},
		audit(status, id) {
			if (status && id) {
				orgApi
					.agreeOrReject({ instituteState: status, id: id })
					.then(res => {
						if (res.code == 0) {
							this.searchModel.current = 1;
							this.getList();
						}
					})
					.catch(e => {
						uni.showToast({
							title: e.msg,
							icon: 'none',
							duration: 1000
						});
					});
			}
		},
		getList() {
			this.moreStatus = 'loading';
			orgApi
				.queryMyPeople(this.searchModel)
				.then(res => {
					if (res.code === 0) {
						if (this.searchModel.current == 1) {
							this.modelList = [];
						}
						if (res.data && res.data.length == 10) {
							this.moreStatus = 'more';
							this.searchModel.current += 1;
							this.modelList = [...this.modelList, ...res.data];
						} else if (res.data && res.data.length < 10) {
							this.moreStatus = 'noMore';
							this.searchModel.current += 1;
							this.modelList = [...this.modelList, ...res.data];
						} else {
							this.moreStatus = 'noMore';
						}
					}
				})
				.catch(e => {
					this.moreStatus = 'noMore';
					uni.showToast({
						title: e.msg,
						icon: 'none',
						duration: 1000,
						
					});
				});
		},
		scrollBottom() {
			this.getList();
		}
	}
};
</script>

<style lang="stylus">
.page_scroll
	position absolute
	top calc(120rpx + var(--status-bar-height))
	right 0rpx
	bottom 0rpx
	left 0rpx
.list
	width 100%
	padding 0rpx 30rpx
	box-sizing border-box
	.list_item
		margin-bottom 60rpx
		display flex
		align-items center
		justify-content space-between
		.list_left
			display flex
			align-items center
			.photo
				width 100rpx
				height 100rpx
				border-radius 50%
			.info
				margin-left 20rpx
				display flex
				flex-direction column
				.name
					font-size 32rpx
					font-family PingFang SC
					font-weight 400
					color #222222
				.date
					margin-top 20rpx
					font-size 24rpx
					font-family PingFang SC
					font-weight 400
					color #999999
		.list_right
			flex 1
			display flex
			justify-content flex-end
			font-size 24rpx
			font-family PingFang SC
			font-weight 400
			.empyt_btn, .solid_btn, .delete_btn
				padding 6rpx 20rpx
				border-radius 24rpx
				border 2rpx solid rgba(153, 153, 153, 1)
			.empyt_btn
				border-color rgba(255, 125, 33, 1)
				color rgba(255, 125, 33, 1)
			.solid_btn
				margin-left 30rpx
				border-color rgba(255, 125, 33, 1)
				background-color rgba(255, 125, 33, 1)
				color rgba(255, 255, 255, 1)
			.delete_btn
				border-color rgba(235, 235, 235, 1)
				background-color rgba(235, 235, 235, 1)
				color rgba(170, 170, 170, 1)
</style>
